// Problem: C. p-binary
// Contest: Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)
// URL: https://codeforces.com/contest/1247/problem/C
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// Create Time : 2023-02-06 17:27:36
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define per(i, a, n) for (int i = n - 1;i >= a;i --)
#define rep(i, a, n) for (int i = a;i < n;i ++)
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)(x).size())
#define PII pair<int, int>
#define int long long
#define PB push_back
#define se second
#define endl "\n"
#define fi first
using namespace std;
const int N = 5e5 + 50, mod = 1e9 + 7, INF = 1e18;
int t, n, m;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
int ok = -1;
rep (i, 1, 32) {
int x = n - m * i, cnt = 0;
if (x < 0) continue;
rep (j, 0, 32) {
if (x >> j & 1) {
cnt ++;
}
}
// 少了并 多了没办法
if (cnt <= i and x >= i) {
ok = i;
break;
}
}
cout << ok << endl;
return 0;
}
1663C - Pōja Verdon | 1497A - Meximization |
1633B - Minority | 688B - Lovely Palindromes |
66B - Petya and Countryside | 1557B - Moamen and k-subarrays |
540A - Combination Lock | 1553C - Penalty |
1474E - What Is It | 1335B - Construct the String |
1004B - Sonya and Exhibition | 1397A - Juggling Letters |
985C - Liebig's Barrels | 115A - Party |
746B - Decoding | 1424G - Years |
1663A - Who Tested | 1073B - Vasya and Books |
195B - After Training | 455A - Boredom |
1099A - Snowball | 1651D - Nearest Excluded Points |
599A - Patrick and Shopping | 237A - Free Cash |
1615B - And It's Non-Zero | 1619E - MEX and Increments |
34B - Sale | 1436A - Reorder |
1363C - Game On Leaves | 1373C - Pluses and Minuses |